package com.InterviewProgram;

import java.util.ArrayList;
import java.util.List;

/**
 * 给定一组字符串 输出所有组合
 * Create by shengong on 2019-06-03 22:15
 */
public class One {

    public static void main(String[] args) {
        Long startTime = System.currentTimeMillis();
        String str = "ab";
        List<String> result = list(str,"");
//        List<String> result = new ArrayList<>();
//        list(str,"",result);
        System.out.println(result);

        // 字符串反转
//        String newStr = Utils.reserve(str);
//        System.out.println(newStr);

        // 不使用中间变量两个值互换
//        int a = 10;
//        int b = 100;
//        a = a*b;
//        b = a/b;
//        a = a/b;
//        System.out.println("a="+ a+",b="+b);

        //===================================================================
        int[] a = {3,21,45,1};
        Utils.selectionSort(a);
        for (int t:a) {
            System.out.println(t);
        }



        System.out.println("耗时："+ (System.currentTimeMillis() - startTime));
    }

    /**
     *
     * @param base 原始数据
     * @param buff 所求字符串的临时结果
     * @return
     */
    public static List<String> list(String base,String buff){
        List<String> result = new ArrayList<>();
        if(base.length() <= 0){
            result.add(buff);
        }
        for(int i = 0; i < base.length(); i++){
            List<String> temp = list(new StringBuilder(base).deleteCharAt(i).toString(),buff+base.charAt(i));
            result.addAll(temp);
        }
        return result;
    }

    /**
     *
     * @param base 基础数据
     * @param buff 临时结果
     * @param result 存放所求结果
     */
    public static void list(String base,String buff,List<String> result){
        if(base.length() <= 0){
            result.add(buff);
        }
        for(int i = 0; i<base.length();i++){
            list(new StringBuilder(base).deleteCharAt(i).toString(),buff + base.charAt(i),result);
        }
    }

}
